% Get all the stock codes of a market
% Input: market_code
% Ouput: list_of_stock_codes
function list_of_stock_codes = getAllStockCodes(market_code, min_num_transactions, min_mean_volume)
    % the query to get all  stocks of a market
       %query = strcat('select s1.Name from security s1, security s2, securityType st1, securityType st2 where s1.ID_SecurityType = st1.ID and st1.Type = ''Stock'' and s2.ID_SecurityType = st2.ID and st2.Type = ''Index'' and 	  s1.ID_Market = s2.ID_Market and s2.Name = ', '''', market_code, '''', ';');
    
    query = strcat('select s1.Name, (select count(*) from security s2, transaction t2 ',...
                            ' where s2.ID = t2.ID_Security and s1.ID = s2.ID and t2.Volume > 0), ', ...
                            '(select avg(t2.Volume) from security s2, transaction t2 ', ... 
                            ' where s2.ID = t2.ID_Security and s1.ID = s2.ID and t2.Volume > 0) ', ...
           'from security s1, security s3 ',...
           ' where (select count(*) from security s2, transaction t2 ',...
                   ' where s2.ID = t2.ID_Security and s1.ID = s2.ID and t2.Volume > 0) > ', mat2str(min_num_transactions),... 
               ' and (select avg(t2.Volume) from security s2, transaction t2 ', ...
                      ' where s2.ID = t2.ID_Security and s1.ID = s2.ID and t2.Volume > 0) > ', mat2str(min_mean_volume),...
               ' and s3.Name = ', '''', market_code, '''', ...
               ' and s1.ID_Market = s3.ID_Market and s3.ID_SecurityType = 1;');
    output_table = selectData(query);    
	
	if (~isempty(output_table)) % exists the result
        list_of_stock_codes = output_table;
    else % not exists the result
        list_of_stock_codes = [];
    end
	
end
